package controller;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.List;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

import dao.StudentDao;
import entity.Student;

public class StudentManage extends JFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private DefaultTableModel dtm;
	private StudentDao sd;
	private List<Student> stus;
	
	public StudentManage() {
		setSize(500, 550);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		setLocationRelativeTo(null);
		

		
		JLabel label=new JLabel("学生信息管理");
		label.setFont(new Font("微软雅黑", Font.TRUETYPE_FONT, 32));
		label.setHorizontalAlignment(JLabel.CENTER);
		add(label,BorderLayout.NORTH);
		
		
		dtm=new DefaultTableModel(new Object[][]{},new String[]{"学号","姓名","性别","操作"});		
		JTable table=new JTable(dtm);
		JScrollPane jsp=new JScrollPane(table);
		add(jsp);
		
		sd=new StudentDao();
		stus=sd.getAll();
		for (Student s : stus) {
			dtm.addRow(s.toArray());
		}
		
	}
	
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			
			@Override
			public void run() {
				new StudentManage();
			}
		});
	}

}
